package com.creative.accountsdk.net.account;

import android.util.Log;

import com.creative.accountsdk.UmsChannel;
import com.creative.accountsdk.net.Protocol;
import com.creative.accountsdk.net.XParams;
import com.creative.util.EncodeUtil;
import com.loopj.android.http.RequestParams;

import org.json.JSONObject;

/**
 * Created by yinjialiang on 15-2-14.
 */
public class LoginProtocol extends Protocol {
    private String username,password;

    public JSONObject jsonUser;

    public LoginProtocol(String username, String password)
    {
        this.username = username;
        this.password = password;
    }

    @Override
    public RequestParams getParams() {
        String base64pwd = EncodeUtil.encryptByBase64(password);
        Log.d(getClass().getSimpleName(), "base64 = " + base64pwd);
        return new XParams().put("loginname", username).put("pwd", base64pwd)
                .put(UmsChannel.PARAM_NAME, UmsChannel.getChannel())
                .getParams();
    }

    @Override
    public String getUrl() {
        return getUrlPrefix()+"login";
    }

    @Override
    protected void parseReturnMap(JSONObject returnMap) {
        jsonUser = returnMap;
    }
}
